<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.system.job.entity.jobName')">
              <a-input placeholder="" v-model="queryParam.jobName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.system.job.entity.jobCode')">
              <a-input placeholder="" v-model="queryParam.jobCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
              <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" v-has="'system:SysJob:add'" type="primary" icon="plus">{{ $t('m.common.button.add') }}</a-button>
      <a-button @click="batchDel" v-has="'system:SysJob:delete'" type="default"  icon="delete" v-test>{{ $t('m.common.button.delete') }}</a-button>
      <a-button type="default" v-has="'system:SysJob:export'" icon="download" @click="handleExportXls($t('m.system.job.other.export_filename'))">{{ $t('m.common.button.export') }}</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button v-has="'system:SysJob:import'" type="default" icon="import">{{ $t('m.common.button.import') }}</a-button>
      </a-upload>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        <template slot="serialNum" slot-scope="text,record,index">
          {{(ipagination.current-1) * ipagination.pageSize + parseInt(index) + 1}}
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'system:SysJob:edit'">{{ $t('m.common.button.update') }}</a>

          <a-divider type="vertical" />
          <a-popconfirm :title="$t('m.common.tip.delete_confirm')" v-has="'system:SysJob:delete'" @confirm="() => handleDelete(record.id)" v-test>
            <a>{{ $t('m.common.button.delete') }}</a>
          </a-popconfirm>
        </span>

      </a-table>

    </div>

    <sysJob-modal ref="modalForm" @ok="modalFormOk"></sysJob-modal>
  </a-card>
</template>

<script>

  import { postAction } from '@/api/manage'
  import { YcListMixin } from '@/mixins/YcListMixin'
  import SysJobModal from './modules/SysJobModal'
  import YchConstant from "@/api/YchConstant";

  export default {
    name: "SysJobList",
    mixins:[YcListMixin],
    components: {
      SysJobModal
    },
    data () {
      return {
        description: '岗位表管理页面',
        // 表头
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            scopedSlots: { customRender: 'serialNum' },
          },
          {
            title:this.$t('m.system.job.entity.jobName'),
            align:"center",
            dataIndex: 'jobName'
          },
          {
            title:this.$t('m.system.job.entity.jobCode'),
            align:"center",
            dataIndex: 'jobCode'
          },
          {
            title:this.$t('m.system.job.entity.jobOrder'),
            align:"center",
            dataIndex: 'jobOrder'
          },
          {
            title:this.$t('m.system.job.entity.description'),
            align:"center",
            dataIndex: 'description'
          },
          {
            title: this.$t('m.common.label.operate'),
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: YchConstant.PREFIX_SYSTEM + "/sysJob/list",
          delete: YchConstant.PREFIX_SYSTEM + "/sysJob/delete",
          deleteBatch: YchConstant.PREFIX_SYSTEM + "/sysJob/deleteBatch",
          exportXlsUrl: YchConstant.PREFIX_SYSTEM + "/sysJob/exportExcel",
          importExcelUrl: YchConstant.PREFIX_SYSTEM + "/sysJob/importExcel",
        },
        dictOptions:{
        },
        /* 排序参数 */
        isorter:{
          column: 'jobOrder',
          order: 'asc',
        }
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${bootConfig[process.env.NODE_ENV].VUE_APP_API}${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      async save() {
        const $table = this.$refs.xTable
        const {insertRecords, removeRecords, updateRecords} = $table.getRecordset()
        if (insertRecords.length <= 0 && removeRecords.length <= 0 && updateRecords.length <= 0) {
          // //console.log("数据未改动！")
          return
        }
        const errMap = await $table.validate().catch(errMap => errMap)
        if (errMap) {
          return
        }
        this.loading = true
        try {
          const body = {insertRecords, removeRecords, updateRecords}
          postAction(YchConstant.PREFIX_SYSTEM + "/sysJob/save", body).then((res) => {
            if (res.success) {
              this.loadData()
              this.messageUtil.success(res.message)
            } else {
              this.messageUtil.warning(res.message)
            }
          })
        } catch (e) {
        }
        this.loading = false
      }

    }
  }
</script>
<style lang="less" scoped>

</style>
